package com.mashibing.tank;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

/**
 * Copyright (C) 2024 - 2024 Jasonakeke， Inc. All Rights Reserved
 *
 * @Desc :
 * @Time : 2024/10/27 21:19
 * @Author : Code_By_Jasonakeke
 * @Email : 2284037977@qq.com
 * @Class : ImageUtil
 * @IDE : IntelliJ IDEA
 */
public class ImageUtil {

	public static BufferedImage rotateImage(final BufferedImage bufferedImage, final int degree) {
		int width = bufferedImage.getWidth();
		int height = bufferedImage.getHeight();
		int type = bufferedImage.getColorModel().getTransparency();
		BufferedImage img;
		Graphics2D graphics2D;
		(graphics2D = (img = new BufferedImage(width, height, type)).createGraphics()).setRenderingHint(
				RenderingHints.KEY_INTERPOLATION,
				RenderingHints.VALUE_INTERPOLATION_BILINEAR
		);
		graphics2D.rotate(Math.toRadians(degree), width / 2, height / 2);
		graphics2D.drawImage(bufferedImage, 0, 0, null);
		graphics2D.dispose();
		return img;
	}
}
